package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduRatingLikeDTO;
import com.zenith.edu.po.vo.EduRatingLikeVO;
import com.zenith.edu.service.EduRatingLikeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/rating-like")
@Tag(name = "课程评价点赞管理", description = "课程评价点赞管理接口")
public class EduRatingLikeController {
    
    @Autowired
    private EduRatingLikeService eduRatingLikeService;
    
    @SecurePostMapping(value = "/createRatingLike", roles = "ROLE_ADMIN", permission = "rating-like:create")
    @Operation(summary = "创建课程评价点赞记录")
    public Result<EduRatingLikeVO> createRatingLike(@RequestBody EduRatingLikeDTO dto) {
        EduRatingLikeVO ratingLikeVO = eduRatingLikeService.createRatingLike(dto);
        return Result.success(ratingLikeVO);
    }
    
    @SecurePostMapping(value = "/getRatingLikeById/{id}", roles = "ROLE_ADMIN", permission = "rating-like:read")
    @Operation(summary = "根据ID获取课程评价点赞记录详情")
    public Result<EduRatingLikeVO> getRatingLikeById(@PathVariable Long id) {
        EduRatingLikeVO ratingLikeVO = eduRatingLikeService.getRatingLikeById(id);
        if (ratingLikeVO == null) {
            return Result.fail("课程评价点赞记录不存在");
        }
        return Result.success(ratingLikeVO);
    }
    
    @SecurePostMapping(value = "/updateRatingLike", roles = "ROLE_ADMIN", permission = "rating-like:update")
    @Operation(summary = "更新课程评价点赞记录信息")
    public Result<EduRatingLikeVO> updateRatingLike(@RequestBody EduRatingLikeDTO dto) {
        EduRatingLikeVO ratingLikeVO = eduRatingLikeService.updateRatingLike(dto);
        return Result.success(ratingLikeVO);
    }
    
    @SecurePostMapping(value = "/deleteRatingLike/{id}", roles = "ROLE_ADMIN", permission = "rating-like:delete")
    @Operation(summary = "删除指定课程评价点赞记录")
    public Result<Void> deleteRatingLike(@PathVariable Long id) {
        boolean result = eduRatingLikeService.deleteRatingLike(id);
        if (!result) {
            return Result.fail("课程评价点赞记录删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getRatingLikeList", roles = "ROLE_ADMIN", permission = "rating-like:read")
    @Operation(summary = "获取课程评价点赞记录列表")
    public Result<List<EduRatingLikeVO>> getRatingLikeList() {
        List<EduRatingLikeVO> ratingLikeList = eduRatingLikeService.getRatingLikeList();
        return Result.success(ratingLikeList);
    }
}